package com.frxuexi.park2212.visit

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.frxuexi.lib_base.base.BaseActivity
import com.frxuexi.park2212.R
import com.frxuexi.park2212.databinding.ActivityVisitApproveBinding
import dagger.hilt.android.AndroidEntryPoint

@Route(path = "/app/VisitApproveActivity")
@AndroidEntryPoint
class VisitApproveActivity : BaseActivity<ActivityVisitApproveBinding, VisitViewModel>() {

    @Autowired
    lateinit var vid: String
    override fun initData() {
        vm.getVisitById.observe(this){
            binding.bean=it
            if(it.visitStatus=="待审核"){
                binding.visitdetailGroup.visibility=View.VISIBLE
            }
        }

        vm.approveVisit.observe(this){
            ToastUtils.showLong("审核通过")
            finish()
        }

        vm.rejectVisit.observe(this){
            ToastUtils.showLong("驳回完成")
            finish()
        }
    }

    override fun initView() {
        ARouter.getInstance().inject(this)
        vm.getVisitById(vid.toInt())

        binding.visitdetailBtn.setOnClickListener {
            val buttonId = binding.visitdetailRg.checkedRadioButtonId
            if(buttonId==R.id.visitdetail_yes){//通过
                vm.approveVisit(vid.toInt())
            }else{//驳回
                vm.rejectVisit(vid.toInt())
            }
        }

    }


}